package config;

import bean.Cat;
import bean.Person;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

@Import({Person.class,MyConfig.MyImportRegister.class})
@Configuration
public class MyConfig {

//    @Bean
//    public Person person(){
//        Person person = new Person();
//        person.setName("xiaoha");
//        person.setAge(12);
//        return person;
//    }


    /**
     * BeanDefinitionRegistry Bean定义信息的注册中心
     *
     * beanDefinition
     */
    static class MyImportRegister implements ImportBeanDefinitionRegistrar{
        @Override
        public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
                                            BeanDefinitionRegistry registry) {

            RootBeanDefinition beanDefinition = new RootBeanDefinition();
            beanDefinition.setBeanClass(Cat.class);
            registry.registerBeanDefinition("tomCat",beanDefinition);
        }
    }
}
